<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
use Common\Model\User;
class MemberController extends Controller{
	public function index(){		
		View::make();
	}
//	注册
	public function reg(){
		if(IS_AJAX){
//			p(123);
			$userModel=new User;
			if(!$userModel->store()){
			$this->ajax(['status'=>false,'message'=>$userModel->getError()]);
		}else{
			$this->ajax(['status'=>true,'message'=>'注册成功']);
		}
		}
		View::make();
	}
//	登录
	public function login(){
		if(IS_AJAX){
			$userModel=new User;
			$code=Q('post.code');
			if(strtolower($code)!=strtolower($_SESSION['code'])){
				$this->ajax(['status'=>false,'message'=>'验证码错误']);
			}
				
			
			
			$username=Q('post.username');			
			$userData=$userModel->where("username={$username}")->find();
			if(!$userData){
				$this->ajax(['status'=>false,'message'=>'用户名不存在']);
			}
			
			$password=Q('post.password','','md5');
			if($password!=$userData['password']){
				$this->ajax(['status'=>false,'message'=>'密码错误']);
			}else{
				$this->ajax(['status'=>true,'message'=>'登录成功']);
			}
			
			
		}
		
		
		View::make();
	}
//	退出
	public function out(){
		
	}
//	验证码
	public function code(){
		
		Code::num(4)->make();
	}
}
